package com.yugao.fintech.antelope.system.manager;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yugao.fintech.antelope.base.model.constants.CommonCons;
import com.yugao.fintech.antelope.system.mapper.SysTenantPackageMapper;
import com.yugao.fintech.antelope.system.model.entity.SysTenantPackage;
import com.yugao.fintech.framework.assistant.utils.exception.BizException;
import org.springframework.stereotype.Service;

import java.util.Objects;

import static com.yugao.fintech.antelope.system.constants.SysErrorEnum.TENANT_PACKAGE_DISABLE;
import static com.yugao.fintech.antelope.system.constants.SysErrorEnum.TENANT_PACKAGE_NOT_EXISTS;

/**
 * 租户套餐
 *

 */
@Service
public class SysTenantPackageManager extends ServiceImpl<SysTenantPackageMapper, SysTenantPackage> {

    /**
     * 校验租户套餐
     *
     * @param id 编号
     * @return 租户套餐
     */
    public SysTenantPackage validTenantPackage(Long id) {
        if (Objects.isNull(id)) {
            return null;
        }
        SysTenantPackage tenantPackage = this.getById(id);
        if (tenantPackage == null) {
            throw new BizException(TENANT_PACKAGE_NOT_EXISTS);
        }
        if (CommonCons.DISABLE.equals(tenantPackage.getStatus())) {
            throw new BizException(TENANT_PACKAGE_DISABLE);
        }
        return tenantPackage;
    }

    public SysTenantPackage getPackageById(Long packageId) {
        return this.getById(packageId);
    }
}
